#include "net.hpp"
#include<unistd.h>
#include "dispatcher.hpp"
#include "../client/rpc_client.hpp"
#include "../client/Requestor.hpp"

void onMessage(const Json::Value& result)
{
  ILOG("result:%d",(int)result.asInt());
}
int main()
{
  //  auto requestor = std::make_shared<bitrpc::client::Requestor>();
  //  auto caller = std::make_shared<bitrpc::client::RpcCaller>(requestor);


  //  auto disp = bitrpc::MessageFactory::create<bitrpc::dispatcher>();
  //  auto cb = std::bind(&bitrpc::client::Requestor::onResponse,requestor.get(),std::placeholders::_1,std::placeholders::_2);
  //  disp->registerHandler<bitrpc::BaseMessage>(bitrpc::MessageType::RSP_RPC,cb);
  //  //  disp->registerHandler<bitrpc::RpcResponse>(bitrpc::MessageType::RSP_RPC,onMessage);
  //   auto method = std::bind(&bitrpc::dispatcher::onMessage,disp.get(),std::placeholders::_1,std::placeholders::_2);
    
  //   auto cl = bitrpc::ClientFactory::create("127.0.0.1",9090);
  //   cl->connect();
  //   cl->setMessageCallback(method);
    
  //   auto conn = cl->connection();
  bitrpc::client::RpcClient client(false,"127.0.0.1",9090);
    Json::Value params,result;
    params["num1"]=11;
    params["num2"]=22;
    int ret = client.call("Add",params,result);
    if(ret !=false)
    {
      std::cout<<"result::"<<result.asInt()<<std::endl;
    }


   //   Json::Value params;
   //  params["num1"]=11;
   //  params["num2"]=22;
   //  bitrpc::client::RpcCaller::JsonAsyncResponse res_future ;
   //  int ret = caller->call(conn,"Add",params,res_future);
   //  if(ret !=false)
   //  {
   //    std::cout<<"result::"<<res_future.get().asInt()<<std::endl;
   //  }
 

  //   Json::Value params;
  //   params["num1"]=11;
  //   params["num2"]=22;
  //  //  bitrpc::client::RpcCaller::JsonAsyncResponse res_future ;
  //   int ret = caller->call(conn,"Add",params,onMessage);
  //   if(ret !=false)
  //   {
  //     //std::cout<<"result::"<<res_future.get().asInt()<<std::endl;
  //   }
    sleep(10);
    return 0;
}